package com.recsmile.sgs.ui.components;

import com.recsmile.sgs.Constants;
import com.recsmile.sgs.entity.Activatable;
import com.recsmile.sgs.entity.GamePanel;
import com.recsmile.sgs.entity.HeroOriginal;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Administrator on 2016/8/26.
 */
public class HeroGui extends JButton implements Activatable {
    private static final long serialVersionUID = 5926706015812873971L;

    private HeroOriginal hero;
    public static final int WIDTH = CardRackGui.HEIGHT;
    public static final int HEIGHT = WIDTH;
    private boolean activated = false;

    public HeroGui(GamePanel panel) {
        hero = null;
        setEnabled(false);
        setSize(WIDTH, HEIGHT);
        setFont(new Font(Font.MONOSPACED, Font.BOLD, 50));
        setLocation(GamePanelGui.WIDTH - LifebarGui.WIDTH - WIDTH, GamePanelGui.HEIGHT - HEIGHT);
        addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                panel.getCurrentOperation().onSelfClicked(HeroGui.this);
            }
        });
    }

    public void setHero(HeroOriginal hero) {
        this.hero = hero;
    }

    @Override
    public synchronized void setActivatable(boolean activatable) {
        setEnabled(activatable);
    }

    @Override
    public synchronized void setActivated(boolean activated) {
        this.activated = activated;
        repaint();
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        if (activated)
            g.setColor(Color.RED);
        else
            g.setColor(Color.BLACK);
        ((Graphics2D) g).setStroke(new BasicStroke(Constants.BORDER_WIDTH));
        g.drawRect(0, 0, WIDTH, HEIGHT);
    }
}
